﻿Imports System.Data.SqlClient

Public Class Dcostos

    Inherits Conexion
    Dim cmd As SqlCommand

    

    Public Function llenarcombocostostipo(ByVal LISTA As String) As DataTable
        Try
            conectado()

            cmd = New SqlCommand("sp_costostipo")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            cmd.Parameters.AddWithValue("@F5", LISTA)
            

            Dim DA As New SqlDataAdapter(cmd)
            Dim TABLA As New DataTable
            TABLA.Clear()
            DA.Fill(TABLA)
            Return TABLA
            Return Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function


    Public Function llenarcombocostostipo2(ByVal LISTA As String) As DataTable
        Try
            conectado()

            cmd = New SqlCommand("sp_costostipo2")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            cmd.Parameters.AddWithValue("@F6", LISTA)

            Dim DA As New SqlDataAdapter(cmd)
            Dim TABLA As New DataTable
            TABLA.Clear()
            DA.Fill(TABLA)
            Return TABLA
            Return Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function

    Dim ocnn As New Conexion
    Public Function buscarCosto(ByVal costor As Entidades.Ecostos) As List(Of Entidades.Ecostos)


        'Dim costos As New List(Of Entidades.Ecostos)

        'Try
        '    conectado()

        '    cmd = New SqlCommand("sp_buscarcostos")
        '    cmd.CommandType = CommandType.StoredProcedure
        '    cmd.Connection = cnn


        '    cmd.Parameters.AddWithValue("@F1", costor.F1)
        '    cmd.Parameters.AddWithValue("@F6", costor.F6)


        '    Dim dr As SqlDataReader = cmd.ExecuteReader

        '    Do While dr.Read

        '        Dim cos As New Entidades.Ecostos
        '        cos.F8R = dr("F8").ToString
        '        cos.F9R = dr("F9").ToString
        '        cos.F10R = dr("F10").ToString
        '        cos.F9R = dr("F9").ToString
        '        cos.F10R = dr("F10").ToString
        '        cos.F11R = dr("F11").ToString
        '        cos.F12R = dr("F12").ToString
        '        cos.F13R = dr("F13").ToString
        '        cos.F14R = dr("F14").ToString
        '        cos.F15R = dr("F15").ToString
        '        cos.F16R = dr("F16").ToString
        '        cos.F17R = dr("F17").ToString
        '        cos.F18R = dr("F18").ToString
        '        cos.F19R = dr("F19").ToString
        '        cos.F20R = dr("F20").ToString
        '        cos.F21R = dr("F21").ToString
        '        cos.F22R = dr("F22").ToString
        '        cos.F23R = dr("F23").ToString

        'cos.F8 = dr("F8").ToString
        'cos.F9 = dr("F9").ToString
        'cos.F10 = dr("F10").ToString
        'cos.F11 = dr("F11").ToString
        'cos.F12 = dr("F12").ToString
        'cos.F13 = dr("F13").ToString
        'cos.F14 = dr("F14").ToString
        'cos.F15 = dr("F15").ToString
        'cos.F16 = dr("F16").ToString
        'cos.F17 = dr("F17").ToString
        'cos.F18 = dr("F18").ToString
        'cos.F19 = dr("F19").ToString
        'cos.F20 = dr("F20").ToString
        'cos.F21 = dr("F21").ToString
        'cos.F22 = dr("F22").ToString
        'cos.F23 = dr("F23").ToString
        'cos.F24 = dr("F24").ToString
        'cos.F25 = dr("F25").ToString
        'cos.F26 = dr("F26").ToString
        'cos.F27 = dr("F27").ToString
        'cos.F28 = dr("F28").ToString
        'cos.F29 = dr("F29").ToString
        'cos.F30 = dr("F30").ToString
        'cos.F31 = dr("F31").ToString
        'cos.F32 = dr("F32").ToString

        'costos.Add(costor)
        'costor = Nothing
        '    Loop
        'dr.Close()
        'desconectado()
        'Return costos

        'Catch ex As Exception
        '    Throw New ArgumentException(ex.Message)
        'Finally

        '    costos = Nothing

        'End Try


        Dim costos As New List(Of Entidades.Ecostos)
        Try


            conectado()

            cmd = New SqlCommand("sp_buscarcostos")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn


            'Dim com As New SqlCommand

            cmd.Parameters.AddWithValue("@F1", costor.F1R)
            cmd.Parameters.AddWithValue("@F6", costor.F6R)

            Dim dr As SqlDataReader = cmd.ExecuteReader

            Do While dr.Read
                Dim COST As New Entidades.Ecostos
                COST.F8 = dr("F8").ToString
                COST.F9 = dr("F9").ToString
                COST.F10 = dr("F10").ToString

                costos.Add(COST)
                costos = Nothing
            Loop
            'retornamos los valores encontrados
            dr.Close()
            desconectado()
            Return costos
        Catch ex As Exception
            Throw New ArgumentException(ex.Message)
        Finally
            costor = Nothing
        End Try
    End Function


End Class
